package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.core.AreaService;
import com.fwtai.service.web.GoodsCodeService;
import com.fwtai.service.web.OrderInfoService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 微信支付订单控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @创建日期 2024-02-28 18:03:36
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/orderInfo")
public class OrderInfoController{

  private final OrderInfoService orderInfoService;

  private final GoodsCodeService goodsCodeService;

  private final AreaService areaService;

  public OrderInfoController(final OrderInfoService orderInfoService,final GoodsCodeService goodsCodeService,final AreaService areaService){
    this.orderInfoService = orderInfoService;
    this.goodsCodeService = goodsCodeService;
    this.areaService = areaService;
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('order_info_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(orderInfoService.queryById(id),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('order_info_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(orderInfoService.listData(new PageFormData(request)),response);
  }

  /*获取商品名称下拉框列动态值选项的数据*/
  @PreAuthorize("hasAuthority('order_info_btn_goodsList')")
  @GetMapping("/getGoodsList")
  public void getGoodsList(final HttpServletResponse response){
    ToolClient.responseJson(goodsCodeService.getGoodsList(),response);
  }

  /**获取区域数据用于构建树形*/
  @PreAuthorize("hasAuthority('order_info_btn_area')")
  @GetMapping("/getAreaTree")
  public void getAreaTree(final String kid,final HttpServletResponse response){
    ToolClient.responseJson(areaService.getAreaTree(kid),response);
  }
}